package com.wm.blog_common.enums;

import lombok.AllArgsConstructor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/***
 * @ClassName: LoginType
 * @Author: 半卷流年
 * @Create_time: 2020-04-07
 */
@AllArgsConstructor
public enum LoginType {

    /**
     *
     */
    PASSWORD_LOGIN(0,"账号密码登录"),
    MOBILE_LOGIN(1,"手机号登录")
    ;

    private Integer value;

    private String text;

    public Integer getValue() {
        return value;
    }

    public String getText() {
        return text;
    }

    public static String getText(Integer value){
        List<String> list = Arrays.stream(LoginType.values()).filter(x -> !ObjectUtils.isEmpty(x) && x.value.equals(value)).map(y -> y.text).collect(Collectors.toList());
        return CollectionUtils.isEmpty(list) ? "":list.get(0);
    }


    /**
     * 某个值是否命中枚举值
     * @param type
     * @return
     */
    public static boolean contains(Integer type){
        if(ObjectUtils.isEmpty(type)){
            return false;
        }
        List<Integer> list = Arrays
                .stream(LoginType.values())
                .map(LoginType::getValue)
        .collect(Collectors.toList());
        return list.contains(type);
    }





}
